import org.eclipse.swt.widgets.Display;


public class GUIUpdater extends Thread{

	private Display display;
	private GUI gui;
	private boolean  flag=true;
	public GUIUpdater(Display display,GUI gui)  {
		this.display= display;
		this.gui=gui;
	}
	@Override
	public void run() {
		while (gui.getSimulation().getGenerationCount()<Constants.GENERATION_LIMIT && flag){

			//despacth a repaint to the main window
			display.asyncExec(new Runnable() {
				
				@Override
				public void run() {
					gui.evolveToNextGeneration();
				}
			});
			try {
				Thread.sleep(Constants.REFRESH_INTERVAL);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//despatch end running to the gui
		display.asyncExec(new Runnable() {
			
			@Override
			public void run() {
				gui.endRunning();
			}
		});
		
		
	}
	public void stopSim() {
		flag=false;
		
	}
}
